package myjava3d;

import javax.media.j3d.BranchGroup;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;

import org.jdesktop.j3d.loaders.vrml97.VrmlLoader;

import com.sun.j3d.loaders.Scene;

public class VrmlObject extends BranchGroup {
	private VrmlLoader loader;
	private String WRL_File;
	public Scene scene;
	
	public VrmlObject() {
		//VRML
	    loader = new VrmlLoader();
	    WRL_File="LegoNinjaV1.wrl";
		System.out.println("Die Datei solls sein: " + WRL_File);
		
		try {
			scene = loader.load(WRL_File);
		} catch (Exception e) {
			System.out.println("FEHLER!!! Scene nicht gefunden:");
		}
		
		detach();
		
		if(scene != null) {
			BranchGroup sceneGroup = scene.getSceneGroup();
			sceneGroup.setCapability(BranchGroup.ALLOW_DETACH);
		    sceneGroup.setCapability(BranchGroup.ALLOW_BOUNDS_READ);
			
		    //Skalieren (ist viel zu groß)
		    Transform3D tfsceneGroup = new Transform3D();
		    tfsceneGroup.setScale(0.0013d);
		    
			// diese TG erlaubt "Child"-Elemente, sich an die Gruppe
			// anzuhaengen und deren Inhalte zu Lesen
			TransformGroup examineGroup = new TransformGroup();
			examineGroup.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
			examineGroup.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
			examineGroup.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
			examineGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
			examineGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
			
			examineGroup.setTransform(tfsceneGroup);
		    examineGroup.addChild(sceneGroup);
		    
		    addChild(examineGroup);
		}
	}
}
